/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package tank.models;

import java.util.Vector;

/**
 *
 * @author shengchang
 */
public class Tank extends Vehicle{
    private int speed = 5;
    private int direction = 0;
    private int rotateSpeed = 0;
    private boolean canMove;
    private Turret turret;
    private Vector<Bullet> bulletVector = new Vector<Bullet>();
    
    public Tank()
    {
        this.turret = new Turret();
    }
    
    public int getRotateSpeed() {
        return rotateSpeed;
    }
    
    public Turret getTurret(){
        return turret;
    }
    
    public void setTurret(Turret turret){
        this.turret = turret;
    }    
    
    public void setCanMove(boolean canMove) {
        this.canMove = canMove;
    }

    public boolean getCanMove() {
        return canMove;
    }
    
    public Vector<Bullet> getBulletVector() {
        return bulletVector;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public int getDirection() {
        return direction;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getSpeed() {
        return speed;
    }
    
    public void shotBullet()
    {
        Bullet bullet;
        DirectionInfo directionInfo;
        int bulletX;
        int bulletY;
        double k = turret.directionInfo.getSlope();

        bulletX = x + 25;
        bulletY = y + 25;
        
        bullet = new Bullet(bulletX, bulletY, new DirectionInfo(turret.directionInfo.getDirectionX(),
                                                                turret.directionInfo.getDirectionY(),
                                                                turret.directionInfo.getSlope()));

        bulletVector.add(bullet);
        Thread t = new Thread(bullet);
        t.start();
    }
    
    public boolean canMove(int direction)
    {
        int itemX;
        int itemY;

        switch(direction)
        {

            case 0:
                for(int i = 0; i < Global.map.getItemList().size(); i++)
                {
                    itemX = Global.map.getItemList().get(i).getX();
                    itemY = Global.map.getItemList().get(i).getY();
                    if( (itemY + 50 >= this.y && itemY < this.y + 50) && (( this.x >= itemX && this.x < itemX + 50 ) ||( this.x + 50 > itemX && this.x + 50 <= itemX + 50 )))
                    {
                        return false;
                    }
                }
                break;
            case 1:
                for(int i = 0; i < Global.map.getItemList().size(); i++)
                {
                    itemX = Global.map.getItemList().get(i).getX();
                    itemY = Global.map.getItemList().get(i).getY();
                    if( (itemX <= this.x + 50 && itemX + 50 > this.x) && (( this.y >= itemY&& this.y < itemY + 50 ) ||( this.y + 50 > itemY && this.y + 50 <= itemY + 50 )))
                    {
                        return false;
                    }
                }
                break;
            case 2:
                for(int i = 0; i < Global.map.getItemList().size(); i++)
                {
                    itemX = Global.map.getItemList().get(i).getX();
                    itemY = Global.map.getItemList().get(i).getY();
                    if( (itemY <= this.y + 50 && itemY + 50 > this.y ) && (( this.x >= itemX && this.x < itemX + 50 ) ||( this.x + 50 > itemX && this.x + 50 <= itemX + 50 )))
                    {
                        return false;
                    }
                }
                break;
            case 3:
                for(int i = 0; i < Global.map.getItemList().size(); i++)
                {
                    itemX = Global.map.getItemList().get(i).getX();
                    itemY = Global.map.getItemList().get(i).getY();
                    if( (itemX + 50 >= this.x && itemX < this.x + 50) && (( this.y >= itemY&& this.y < itemY + 50 ) ||( this.y + 50 > itemY && this.y + 50 <= itemY + 50 )))
                    {
                        return false;
                    }
                }
                break;
        }

        return true;
    }
}
